 package com.xc.controller.backend;

 import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.google.common.collect.Maps;
import com.xc.common.ServerResponse;
import com.xc.pojo.Stock;
import com.xc.pojo.StockAllotment;
import com.xc.pojo.StockBlockTrade;
import com.xc.service.IStockService;

@Controller
@RequestMapping({"/admin/stock/"})
public class AdminStockController {
     private static final Logger log = LoggerFactory.getLogger(AdminStockController.class);

     @Autowired
     IStockService iStockService;

     //查询产品管理 所以股票信息及模糊查询
     @RequestMapping({"list.do"})
     @ResponseBody
     public ServerResponse list(@RequestParam(value = "showState", required = false) Integer showState, @RequestParam(value = "lockState", required = false) Integer lockState, @RequestParam(value = "code", required = false) String code, @RequestParam(value = "name", required = false) String name, @RequestParam(value = "stockPlate", required = false) String stockPlate, @RequestParam(value = "stockType", required = false) String stockType, @RequestParam(value = "pageNum", defaultValue = "1") int pageNum, @RequestParam(value = "pageSize", defaultValue = "10") int pageSize, HttpServletRequest request) {
         return this.iStockService.listByAdmin(showState, lockState, code, name, stockPlate, stockType, pageNum, pageSize, request);
     }

    /**
     * 大宗交易列表
     *
     * @param stockName 股票名称
     * @param stockCode 股票代码
     * @param pageNum 页码
     * @param pageSize 页大小
     * @return 返回结果
     */
     @RequestMapping({"listAllotment.do"})
     @ResponseBody
     public ServerResponse listAllotment(@RequestParam(value = "stockName", required = false) String stockName,
                                         @RequestParam(value = "stockCode", required = false) String stockCode,
                                         @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                         @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
         return this.iStockService.listAllotment(stockName, stockCode, pageNum, pageSize);
     }
     //股票配售列表
     @RequestMapping({"listBlockTrade.do"})
     @ResponseBody
     public ServerResponse listBlockTrade(@RequestParam(value = "showState", required = false) Integer showState, @RequestParam(value = "lockState", required = false) Integer lockState, @RequestParam(value = "code", required = false) String code, @RequestParam(value = "pageNum", defaultValue = "1") int pageNum, @RequestParam(value = "pageSize", defaultValue = "10") int pageSize, HttpServletRequest request) {
    	 return this.iStockService.listBlockTrade(showState, lockState, code, pageNum, pageSize, request);
     }

     //新股申购记录
     @RequestMapping({"listNewStockApply.do"})
     @ResponseBody
     public ServerResponse listNewStockApply( @RequestParam(value = "pageNum", defaultValue = "1") int pageNum, @RequestParam(value = "pageSize", defaultValue = "10") int pageSize, 
    		 @RequestParam(value = "userId", required = false) Integer userId, 
    		 @RequestParam(value = "phone", required = false) String phone, 
    		 @RequestParam(value = "agentName", required = false) String agentName, 
    		 @RequestParam(value = "agentId", required = false) Integer agentId, 
    		 @RequestParam(value = "nickName", required = false) String nickName, 
    		 HttpServletRequest request) {
    	 Map<String, Object> map = Maps.newHashMap();
    	 map.put("userId", userId);
    	 map.put("phone", phone);
    	 map.put("agentName", agentName);
    	 map.put("agentId", agentId);
    	 map.put("nickName", nickName);
         return this.iStockService.listNewStockApply(pageNum, pageSize, map, request);
     }
     
     @RequestMapping({"listStockAllotmentApply.do"})
     @ResponseBody
     public ServerResponse listStockAllotmentApply( @RequestParam(value = "pageNum", defaultValue = "1") int pageNum, @RequestParam(value = "pageSize", defaultValue = "10") int pageSize, 
    		 @RequestParam(value = "userId", required = false) Integer userId, 
    		 @RequestParam(value = "phone", required = false) String phone, 
    		 @RequestParam(value = "agentName", required = false) String agentName, 
    		 @RequestParam(value = "agentId", required = false) Integer agentId, 
    		 @RequestParam(value = "nickName", required = false) String nickName, 
    		 HttpServletRequest request) {
    	 Map<String, Object> map = Maps.newHashMap();
    	 map.put("userId", userId);
    	 map.put("phone", phone);
    	 map.put("agentName", agentName);
    	 map.put("agentId", agentId);
    	 map.put("nickName", nickName);
    	 return this.iStockService.listStockAllotmentApply(pageNum, pageSize, map, request);
     }

     //审核新股中签与否
     @RequestMapping({"opNewStockApply.do"})
     @ResponseBody
     public ServerResponse opNewStockApply( @RequestParam(value = "id") int id, @RequestParam(value = "state") int state, @RequestParam(required = false, value = "passNum") Integer passNum) throws Exception {
         return this.iStockService.opNewStockApply(id,state, passNum);
     }

     //新股申购记录
     @RequestMapping({"listStockBlockTradeApply.do"})
     @ResponseBody
     public ServerResponse listStockBlockTradeApply( @RequestParam(value = "pageNum", defaultValue = "1") int pageNum, @RequestParam(value = "pageSize", defaultValue = "10") int pageSize, 
    		 @RequestParam(value = "userId", required = false) Integer userId, 
    		 @RequestParam(value = "phone", required = false) String phone, 
    		 @RequestParam(value = "agentName", required = false) String agentName, 
    		 @RequestParam(value = "agentId", required = false) Integer agentId, 
    		 @RequestParam(value = "nickName", required = false) String nickName, 
    		 HttpServletRequest request) {
    	 Map<String, Object> map = Maps.newHashMap();
    	 map.put("userId", userId);
    	 map.put("phone", phone);
    	 map.put("agentName", agentName);
    	 map.put("agentId", agentId);
    	 map.put("nickName", nickName);
    	 return this.iStockService.listStockBlockTradeApply(pageNum, pageSize, map, request);
     }
     
     //审核新股中签与否
     @RequestMapping({"opStockBlockTradeApply.do"})
     @ResponseBody
     public ServerResponse opStockBlockTradeApply( @RequestParam(value = "id") int id, @RequestParam(value = "state") int state, @RequestParam(required = false, value = "passNum") Integer passNum) throws Exception {
    	 return this.iStockService.opStockBlockTradeApply(id,state, passNum);
     }
     //审核新股中签与否
     @RequestMapping({"opStockAllotmentApply.do"})
     @ResponseBody
     public ServerResponse opStockAllotmentApply(@RequestParam(value = "id") int id, @RequestParam(value = "state") int state, @RequestParam(required = false, value = "passNum") Integer passNum) throws Exception {
    	 return this.iStockService.opStockAllotmentApply(id,state, passNum);
     }


     //修改产品管理 股票是否锁定
     @RequestMapping({"updateLock.do"})
     @ResponseBody
     public ServerResponse updateLock(Integer stockId) {
         return this.iStockService.updateLock(stockId);
     }

     //修改产品管理 股票状态
     @RequestMapping({"updateShow.do"})
     @ResponseBody
     public ServerResponse updateShow(Integer stockId) {
         return this.iStockService.updateShow(stockId);
     }

     //添加产品管理 股票信息
     @RequestMapping({"add.do"})
     @ResponseBody
     public ServerResponse add(@RequestParam(value = "stockName", required = false) String stockName, @RequestParam(value = "stockCode", required = false) String stockCode, @RequestParam(value = "stockType", required = false) String stockType, @RequestParam(value = "stockPlate", required = false) String stockPlate, @RequestParam(value = "isLock", required = false) Integer isLock, @RequestParam(value = "isShow", required = false) Integer isShow) {
         return this.iStockService.addStock(stockName, stockCode, stockType, stockPlate, isLock, isShow);
     }

     //添加股票配售
     @RequestMapping({"addAllotment.do"})
     @ResponseBody
     public ServerResponse addAllotment(StockAllotment model) {
         return this.iStockService.addAllotment(model);
     }
     //添加股票配售
     @RequestMapping({"addBlockTrade.do"})
     @ResponseBody
     public ServerResponse addBlockTrade(StockBlockTrade model) {
    	 return this.iStockService.addBlockTrade(model);
     }

     //修改股票配售信息
     @RequestMapping({"updateStockBlockTrade.do"})
     @ResponseBody
     public ServerResponse updateStockBlockTrade(StockBlockTrade model) {
         return this.iStockService.updateStockBlockTrade(model);
     }
     //修改股票配售信息
     @RequestMapping({"updateStockAllotment.do"})
     @ResponseBody
     public ServerResponse updateStockAllotment(StockAllotment model) {
    	 return this.iStockService.updateStockAllotment(model);
     }


     //修改票信息
     @RequestMapping({"updateStock.do"})
     @ResponseBody
     public ServerResponse updateStock(Stock model) {
         return this.iStockService.updateStock(model);
     }

     //删除股票
     @RequestMapping({"delStock.do"})
     @ResponseBody
     public ServerResponse deleteByPrimaryKey(Integer id) {
         return this.iStockService.deleteByPrimaryKey(id);
     }



 }